// 下载仓库中的代码
const download = require('download-git-repo')
// 提示用户的loading
const ora = require('ora')
// 命令行渲染工具
const chalk = require('chalk')
// 下载的方法
const downloadFun = (url, projectName) => {
    const spinner = ora()
    spinner.start()
    spinner.text = chalk.red('代码正在下载...')
    download('direct:' + url, projectName, {clone: true}, (err) => {
        if (!err) {
            spinner.succeed(chalk.green('代码下载成功'))
            console.log(chalk.green.bold('Done! you run:'))
            console.log(chalk.blue('cd ' + projectName))
            console.log(chalk.blue('npm install'))
            console.log(chalk.blue('npm run dev'))
        } else {
            spinner.fail('代码下载失败')
        }
    })
}

module.exports = downloadFun
